from django.db import models
from account.models import Users
from common.db import DbModel
from products.models import Product
from django.utils import timezone
from django.core.validators import MinValueValidator, MaxValueValidator
from orders.models import Order
# Create your models here.

class Review(models.Model):
    """用户评论表"""
    user = models.ForeignKey(Users, on_delete=models.CASCADE, related_name='comments', verbose_name='用户')
    product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='comments', verbose_name='商品')
    content = models.TextField(verbose_name='评论内容')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='评论时间')
    likes = models.PositiveIntegerField(default=0, verbose_name='评论点赞数量')
    status = models.BooleanField(default=False, verbose_name='评论状态')
    rating = models.PositiveIntegerField(
        verbose_name='打星等级',
        validators=[MinValueValidator(1), MaxValueValidator(5)]
    )

    class Meta:
        db_table = 'comments'
        verbose_name = '评论表'
        verbose_name_plural = '评论表'

    def __str__(self):
        return f'{self.user.username} - {self.product.title}'
class Feedback(models.Model):
    """用户反馈模型"""
    id = models.AutoField(primary_key=True, verbose_name='反馈ID')
    user = models.ForeignKey(Users, on_delete=models.CASCADE, related_name='feedbacks', verbose_name='用户')
    contact_info = models.CharField(max_length=100, verbose_name='联系方式')
    content = models.TextField(verbose_name='反馈内容')
    order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name='feedbacks', verbose_name='订单ID')
    display_slider = models.BooleanField(default=False, verbose_name='是否展示轮图')

    class Meta:
        db_table = 'feedbacks'
        verbose_name = '用户反馈表'
        verbose_name_plural = '用户反馈表'

    def __str__(self):
        return f'反馈ID: {self.id} - 用户: {self.user.username}'